package com.epam;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class Application {

	public static Ship spaceship = new Ship();

	public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
	List<Droid> zadrot=new ArrayList<Droid>();
	zadrot.add(new Droid("first",50,150));
	zadrot.add(new Droid("second",75,200));
	zadrot.add(new Droid("third",100,250));
	zadrot.add(new Droid("fourth",125,250));
	
	spaceship.setDroids(zadrot);
	
	//serialization
	try{
	ObjectOutputStream out =new ObjectOutputStream(new FileOutputStream("droids.dat"));
		out.writeObject(spaceship);
		}
		catch(FileNotFoundException e){
		e.printStackTrace();
		}
		catch(IOException e){
			e.printStackTrace();
		}

	//deserialization
	try{
		ObjectInputStream in=new ObjectInputStream(new FileInputStream("droids.dat"));
		Ship droidFromFile=(Ship) in.readObject();
		System.out.println(droidFromFile);
		in.close();
	}catch(ClassCastException e){
		e.printStackTrace();
	}catch(FileNotFoundException e){
		e.printStackTrace();
	}catch(IOException e){
		e.printStackTrace();
	}
	
}
}
